package com.fr.sort;
/**
 * @author furong
 * @version 创建时间：2016-4-28 下午6:00:20
 */
public class InsertSort extends ShowSort{
	public static void insertSort(int [] a){
		int n = a.length;
		for (int i = 1; i < n; i++){
			if (a[i] < a[i-1]){
				int j = i - 1;
				int x = a[i];
				a[i] = a[i-1];
				while (j >= 0){
					if (x >= a[j]){
						a[j + 1] = x;
						break;
					}else{
						a[j + 1] = a[j];
					}
					j --;
				}
				if (j < 0){
					a [0] = x;
				}
			}
			show(i, a);
		}
	}
}
